﻿#include "UdpCodec_TurnTable.h"

#include "TurnTableCodec.h"
#include "TransmitCodec.h"

UdpCodec_TurnTable::UdpCodec_TurnTable()
{
  setObjectName(getClassNameFirstLow<UdpCodec_TurnTable>());
}

UdpCodec_TurnTable::~UdpCodec_TurnTable()
{}

DataPackage_UdpCodec* UdpCodec_TurnTable::decode(DataPackage_UdpCodec* dataPackageInfo_Device)
{
  //等待实现
  QByteArray data=dataPackageInfo_Device->getData();
  uint deviceId=dataPackageInfo_Device->getDeviceId();
  if(data.isEmpty())
    {// 数据体为空代表是对下发指令的确认， 发送至转发管理器
      transmitCodec->decode_udp(deviceId,dataPackageInfo_Device->getMsgId(),dataPackageInfo_Device->getPackageType(),data);
    }
  else
    {
      //数据体不为空则需要解析
      turnTableCodec->decode(data,deviceId);
    }
  return Q_NULLPTR;
}

TurnTableCodec* UdpCodec_TurnTable::getTurnTableCodec()const
{
  return turnTableCodec;
}

UdpCodec_TurnTable* UdpCodec_TurnTable::setTurnTableCodec(TurnTableCodec* const turnTableCodec)
{
  this->turnTableCodec=turnTableCodec;
  printInjection(this,turnTableCodec);
  return this;
}

TransmitCodec* UdpCodec_TurnTable::getTransmitCodec()const
{
  return transmitCodec;
}

UdpCodec_TurnTable* UdpCodec_TurnTable::setTransmitCodec(TransmitCodec* const transmitCodec)
{
  this->transmitCodec=transmitCodec;
  printInjection(this,transmitCodec);
  return this;
}

void UdpCodec_TurnTable::objectAutoInjection(QHash<QString,QObject*>* objMap)
{
  setTurnTableCodec(getObjFromMap<TurnTableCodec>(objMap));
  setTransmitCodec(getObjFromMap<TransmitCodec>(objMap));
}
